//index.js
//获取应用实例
var app = getApp()
Page({
  data: {

  },


  onLoad: function () {
    var that = this;

    wx.connectSocket({
      url: 'wss://ws.tdreamer.cc'
    })
    wx.onSocketOpen(function (res) {
      console.log('WebSocket连接已打开！')
      wx.sendSocketMessage({
        data: 'test',
        success: function (res) {
          console.log('websocket链接成功！')
          // console.log(res);
        },
        fail: function () {
          // fail
        },
        complete: function () {
          // complete
        }
      })
    })
    wx.onSocketError(function (res) {
      console.log('WebSocket连接打开失败，请检查！' + JSON.stringify(res))
    })
    wx.onSocketMessage(function (res) {
      // console.log('收到服务器内容：' + res.data)
    })
    wx.onSocketClose(function (res) {
      console.log('WebSocket 已关闭！')
    })

  }

})
